var Mock = require('mockjs')
// 导入数据
var mockUserMain = require('./datas/mockUserMain')
var searchResult = require('./datas/searchArticles')
var loginData = require('./datas/mockLogin')
var auditData = require('./datas/audit')
var userInfo = require('./datas/userInfo')
// 模拟设置延迟时间实现异步请求
Mock.setup({
  timeout: '1000-2000'
})
// 三个参数：请求地址，请求方式，请求返回的数据
// 配置根地址,是否需要加#？
const baseUrl = 'http://localhost:8080'

// 获取密码key加密的秘钥
Mock.mock(`${baseUrl}/user/getPublicKey`, 'get', () => {
  // console.log(loginData.default.encryptKey);
  return loginData.default.encryptKey
})

// 返回用户的登录信息
Mock.mock(`${baseUrl}/api/login`, 'post', (data: any) => {
  var parseData = JSON.parse(data.body)
  // 现在传递的是加密后的密码
  return loginData.default.loginInfo
})

// 返回所有的标签数据
Mock.mock(`${baseUrl}/Tag/findAllTag`, 'get', () => {
  return mockUserMain.default.tagsList
})

// 返回点赞排行榜中近一周的数据
Mock.mock(`${baseUrl}/knowledge/selectHotKnowledgeByLike?timeRange=week`, 'get', (data: any) => {
  // console.log(data);
  return mockUserMain.default.likeRankList
})
// 返回点赞排行榜中近一月的数据
Mock.mock(`${baseUrl}/knowledge/selectHotKnowledgeByLike?timeRange=month`, 'get', (data: any) => {
  // console.log(data);
  return mockUserMain.default.likeRankList
})

// 返回热度排行榜中近一周的数据
Mock.mock(`${baseUrl}/knowledge/selectHotKnowledgeByView?timeRange=week`, 'get', (data: any) => {
  // console.log(data);
  return mockUserMain.default.hotRankList
})
// 返回热度排行榜中近一月的数据
Mock.mock(`${baseUrl}/knowledge/selectHotKnowledgeByView?timeRange=month`, 'get', (data: any) => {
  // console.log(data);
  return mockUserMain.default.hotRankList
})

// 返回首页轮播图图片地址数据
Mock.mock(`${baseUrl}/api/getUserMainCarouselImg`, 'get', () => {
  return mockUserMain.default.carouselImages
})

// 获取首页文章列表数据
Mock.mock(`${baseUrl}/api/getArticleList`, 'post', (data: any) => {
  // console.log(data);
  // console.log(mockUserMain.default.articleList);
  return mockUserMain.default.articleList
})

// 获取普通检索结果的数据
Mock.mock(`${baseUrl}/api/normalSearchArticles`, 'post', (data: any) => {
  console.log(data);
  return searchResult.default.normalSearchResult
})

// 获取高级检索结果的数据
Mock.mock(`${baseUrl}/knowledge/advancedSearch`, 'post', (data: any) => {
  // console.log(data);
  console.log(searchResult.default.advancedSearchResult);

  return searchResult.default.advancedSearchResult
})

// 文章提交
Mock.mock(`${baseUrl}/api/addKnowledge`, 'post', (data: any) => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '提交成功'
  }
})

// 用户七牛云数据上传的token
Mock.mock(`${baseUrl}/api/getQiNiuToken`, 'get', (data: any) => {
  // console.log("1111");

  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      token: '123456'
    }
  }
})

// 自动保存的时间
Mock.mock(`${baseUrl}/api/saveTime`, 'get', () => {
  return {
    'code': 200,
    'msg': '保存成功',
    data: {
      time: "6000"
    }
  }
})

// 用户的基本信息
Mock.mock(`${baseUrl}/api/getUserInfo`, 'post', () => {
  // console.log(userInfo.default);

  return userInfo.default.userInfo
})
//页面初始请求数据
Mock.mock(`${baseUrl}/api/FindKonwledgesByPageInit?Page=1&Size=10&ID=0`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      table: [
        {
          "id": 1,
          "date": "2020-08-01",
          "title": "测试文章1",
          'state': 1
        },
        {
          "id": 2,
          "date": "2020-08-02",
          "title": "测试文章2",
          'state': 2
        }
      ]
    }
  }
})

//分页请求数据
Mock.mock(`${baseUrl}/api/FindKonwledges?Page=2&Size=10&ID=0`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      table: [
        {
          "date": "2020-08-01",
          "title": "测试文章3",
          'state': 1
        },
        {
          "date": "2020-08-02",
          "title": "测试文章4",
          'state': 2
        }
      ]
    }
  }
})

//审核人员查找特定时间状态的知识——搜索按钮
Mock.mock(`${baseUrl}/api/getFindStatus?ParamsObject[status]=&ID=0`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      table: [
        {
          "date": "2020-08-01",
          "title": "测试文章3",
          'state': 1
        },
        {
          "date": "2020-08-02",
          "title": "测试文章4",
          'state': 2
        }
      ]
    }
  }
})

//点击审核按钮
Mock.mock(`${baseUrl}/api/AuditKnowledge?knowledgeId=1`, 'get', () => {
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      ruleForm: {
        id: 10086,
        name: '1',
        label: '2',
        articleType: '3',
        context: '4',
      }
    }
  }
})

//点击审核通过
Mock.mock(`${baseUrl}/api/AuditPass`, 'post', () => {
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      ruleForm: {
        id: 10086,
        name: '1',
        label: '2',
        articleType: '3',
        context: '4',
      }
    }
  }
})

//驳回文章
Mock.mock(`${baseUrl}/api/overrule`, 'post', () => {
  return {
    'code': 200,
    'msg': '驳回成功',
  }
})

//初始分页请求获得标签
Mock.mock(`${baseUrl}/api/FindAdminTagByPage?Page=1&Size=10`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      tagTableData: [
        { id: 1, tagName: "测试标签1" },
        { id: 2, tagName: "测试标签2" },
        { id: 3, tagName: "测试标签3" },
        { id: 4, tagName: "测试标签4" },
        { id: 5, tagName: "测试标签5" }
      ]
    }
  }
})

//添加标签
Mock.mock(`${baseUrl}/api/AddTag?Tag=1234`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '添加成功',
  }
})

//编辑标签
Mock.mock(`${baseUrl}/api/EditTag?OldTag=%E6%B5%8B%E8%AF%95%E6%A0%87%E7%AD%BE1&NewTag=biaoqian`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '编辑成功',
  }
})

//删除标签
Mock.mock(`${baseUrl}/api/DeleteTag?Tag=%E6%B5%8B%E8%AF%95%E6%A0%87%E7%AD%BE5`, 'get', () => {
  // console.log(data);
  console.log("11111");

  return {
    'code': 200,
    'msg': '删除成功',
  }
})

//添加用户
Mock.mock(`${baseUrl}/api/AddUser?Username=1&Role=%E5%AE%A1%E6%A0%B8%E5%91%98&Password=1`, 'get', () => {
  return {
    'code': 200,
    'msg': '添加成功',
  }
})

//编辑用户
Mock.mock(`${baseUrl}/api/EditUser?Username=123&Role=%E7%AE%A1%E7%90%86%E5%91%98&Id=1`, 'get', () => {
  return {
    'code': 200,
    'msg': '编辑成功',
  }
})

//删除用户
Mock.mock(`${baseUrl}/api/DeleteUser?Id=1`, 'get', () => {
  return {
    'code': 200,
    'msg': '删除成功',
  }
})

//搜索用户
Mock.mock(`${baseUrl}/api/FindAdminUserBySearch?Username=1`, 'get', () => {
  return {
    'code': 200,
    'msg': '搜索成功',
    data: {
      'user': [
        {
          'id': 1,
          'name': '1',
          'role': 1,
          'status': 1
        }
      ]
    }
  }
})

//初始分页请求获得人员
Mock.mock(`${baseUrl}/api/FindAdminUserByPage?Page=1&Size=10`, 'get', () => {
  // console.log(data);
  return {
    'code': 200,
    'msg': '获取成功',
    data: {
      'user': [
        {
          'id': 1,
          'name': '1',
          'role': 1,
          'status': 1
        },
        {
          'id': 2,
          'name': '2',
          'role': 2,
          'status': 0
        },
      ]
    }
  }
})

//搜索权重
Mock.mock(`${baseUrl}/api/SearchWeight`, 'get', () => {
  return {
    'code': 200,
    'msg': '改变成功',
  }
})

// 更新用户的个人信息
Mock.mock(`${baseUrl}/api/updateUserInfo`, 'post', (data: any) => {
  console.log(data);

  return userInfo.default.updateUserInfo
})

// 发送验证码
Mock.mock(`${baseUrl}/api/sendVerificationCode`, 'post', (data: any) => {
  return userInfo.default.verifyCode
})

// 拦截请求修改邮箱
Mock.mock(`${baseUrl}/api/changeEmail`, 'post', (data: any) => {
  console.log(data);
  return userInfo.default.changeEmail
})

// 拦截请求修改密码
Mock.mock(`${baseUrl}/api/changePassword`, 'post', (data: any) => {
  console.log(data);
  return userInfo.default.changePassword
})

// 获取知识详情的接口
Mock.mock(`${baseUrl}/knowledge/knowledge_detail?knowledgeId=1`, 'get', (data: any) => {
  return searchResult.default.knowledgeDetail
})

// 获取评论的接口
Mock.mock(`${baseUrl}/knowledge/comment?knowledgeId=1`, 'get', (data: any) => {
  return searchResult.default.commentList
})